#!/usr/bin/python3
# -*- coding:utf-8 -*-
"""
@File: Demo.py
@Author: lijk34925 
@Date: 2024/11/27 18:45
@desc: 请补充本模块功能说明
"""
import os


def read_and_merge_files(directory, output_file, path_split="数据预埋"):
    with open(output_file, 'w', encoding='utf-8') as outfile:
        for root, dirs, files in os.walk(directory):
            for file in files:
                if file.endswith('.sql'):
                    paths = root.split(path_split)
                    file_path = os.path.join(root, file)
                    try:
                        with open(file_path, 'r', encoding='utf-8') as infile:
                            content = infile.read()
                            outfile.write(f"### 场景功能 ： {paths[-1]} ###\n")
                            outfile.write(f"### 场景名称 ： {file} ###\n")
                            outfile.write(f"### 文件内容 ： \n")
                            outfile.write(content)
                            outfile.write(f"### 文件 {file_path} 结尾标志行 ###\n")
                            outfile.write("\n\n\n")  # Add a blank line between files
                    except Exception as e:
                        print(f"Error reading file {file_path}: {e}")


if __name__ == '__main__':
    target_directory = 'E:\AutoTest\Project\金融反洗钱项目\web应用\数据预埋\指标规则\风险评估指标'
    output_file = 'merged_sql_风险评估指标.txt'
    read_and_merge_files(target_directory, output_file)